package com.example.dialog;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.material.bottomsheet.BottomSheetDialog;

public class MainActivity extends AppCompatActivity {
    private String[] str={"抽烟","喝酒","烫头"};
    private  int a =0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        Button button= findViewById(R.id.button),
                button2=findViewById(R.id.button2),
                button3=findViewById(R.id.button3),
                button4=findViewById(R.id.button4),
                button5=findViewById(R.id.button5),
                button6=findViewById(R.id.button6),
                button7=findViewById(R.id.button7),
                button8=findViewById(R.id.button8),
                button9=findViewById(R.id.button9);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
                        .setTitle("我是标题")
                        .setMessage("我是内容")
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您取消了",Toast.LENGTH_LONG).show();
                            }
                        })
                        .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您确认了",Toast.LENGTH_LONG).show();
                            }
                        })
                        .create();
                dialog.show();
            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
                        .setTitle("于谦喜欢什么")
                        .setItems(str, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您选择了"+str[i],Toast.LENGTH_LONG).show();
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您取消了",Toast.LENGTH_LONG).show();
                            }
                        })
                        .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您确认了",Toast.LENGTH_LONG).show();
                            }
                        })
                        .create();
                dialog.show();
            }
        });
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
                        .setTitle("于谦喜欢什么")
                        .setSingleChoiceItems(str, a, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                a=i;
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您取消了",Toast.LENGTH_LONG).show();
                            }
                        })
                        .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您选择了"+str[a],Toast.LENGTH_LONG).show();
                            }
                        })
                        .create();
                dialog.show();
            }
        });
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final boolean c[] = {false, false, false};
                    AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
                            .setTitle("于谦喜欢什么")
                            .setMultiChoiceItems(str,c, new DialogInterface.OnMultiChoiceClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i, boolean b) {
                                    c[i]=b;
                                }
                            })
                            .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Toast.makeText(MainActivity.this,"您取消了",Toast.LENGTH_LONG).show();
                                }
                            })
                            .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    String s="";
                                    for(int d=0;d<c.length;d++)
                                    {
                                       if(c[d])
                                       {
                                           s=s+str[d]+",";
                                       }
                                    }
                                    Toast.makeText(MainActivity.this,"您选择了"+s,Toast.LENGTH_LONG).show();
                                }
                            })
                            .create();
                    dialog.show();
                }
        });
        button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BottomSheetDialog dialog = new BottomSheetDialog(MainActivity.this);
                View views = getLayoutInflater().inflate(R.layout.a, null);
                dialog.setContentView(views);
                dialog.show();
            }
        });
        button6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
                progressDialog.setMessage("Loading..."); // 设置提示信息
                progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); // 设置进度条样式为圆形
                progressDialog.setCanceledOnTouchOutside(true); // 设置点击对话框外部是否取消对话框显示
                progressDialog.show(); // 显示对话框

            }
        });
        button7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
                progressDialog.setMessage("Downloading..."); // 设置提示信息
                progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // 设置进度条样式为水平
                progressDialog.setProgress(0); // 设置初始进度值
                progressDialog.setMax(100); // 设置进度的最大值
                progressDialog.setCanceledOnTouchOutside(true); // 设置点击对话框外部是否取消对话框显示
                progressDialog.show(); // 显示对话框
            }
        });
        button8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LayoutInflater inflater = getLayoutInflater();
                View dialogView = inflater.inflate(R.layout.a, null); // 替换为有效的布局文件引用
               AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
                        .setTitle("我是标题")
                        .setView(dialogView)
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您取消了",Toast.LENGTH_LONG).show();
                            }
                        })
                        .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this,"您确认了",Toast.LENGTH_LONG).show();
                            }
                        })
                        .create();
                dialog.show();
            }
        });
        button9.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    LayoutInflater inflater = getLayoutInflater();
                    View dialogView = inflater.inflate(R.layout.a, null); // 替换为有效的布局文件引用
                    AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
                            .setTitle("我是标题")
                            .setView(dialogView)
                            .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Toast.makeText(MainActivity.this,"您取消了",Toast.LENGTH_LONG).show();
                                }
                            })
                            .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Toast.makeText(MainActivity.this,"您确认了",Toast.LENGTH_LONG).show();
                                }
                            })
                            .create();
                    dialog.show();
                }

        });

    }
}